﻿using MyFileView.Core.Core;
using MyFleView.Core;
using Newtonsoft.Json.Linq;
using Svg;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;

namespace MyFileView.Core.Service
{
    public class ImageFilePreview( IConvertFileFactory convertFileFactory) 
        : AbstractImageDocumentConvert(convertFileFactory)//(documentFormatRegistry)
    {
        public override string[] Name { get; } = new string[] { "jpg", "jpeg", "png", "gif","svg","bmp" };

        public override void FilePreview()
        {
            var path = ConvertFileContext.FileInfo.FullFilePath;
            if (ConvertFileContext.FileInfo.FileSuffix == FileConstant.Svg)
            {
                SvgHandle(path);
            }
            else
            {
                using var images = Image.FromFile(path);
                SetProperty(path, RouteConstant.Picture, images.Width, images.Height);
            }
        }


        public void SvgHandle(string path) 
        {
            var svg=   SvgDocument.Open(path);
            var width = ((int)Math.Round(svg.Width));
            var height = ((int)Math.Round(svg.Height));
          //  Bitmap bitmap= svg.Draw();
            SetProperty(path, RouteConstant.Picture, width, height);

        }
    }
}
